package callback;

import pojo.ChessOnlineRoom;


import transfer.IntegerData;

import util.Utils;
import client.Client;

public class BackToLobbyCallback extends ClientCallback{
	ChessOnlineRoom room;
	public BackToLobbyCallback(Client client,ChessOnlineRoom room) {
		super(client);
		this.room = room;
	}
	
	@Override
	public void perform() { 
		if(room != null){ //back on room view
			if(room.getPlayerA().getUsername().compareTo(Utils.getCurrentUser()) == 0){// owner
				mMainScreen.getCw().sendObject(new IntegerData("Close Room", room.getRoomId()));	
				System.out.println("Back Room Id: "+ room.getRoomId());
			}
			else{ // guess
				mMainScreen.getCw().sendObject(new IntegerData("Quit Room", room.getRoomId()));	
				//mMainScreen.showLobbyView();
			}
		}
		else{ // back when on create room
			if(Utils.getLeagueId() == -1){
				mMainScreen.showLobbyView(false);
				if(Utils.isLeagueMode()){
					mMainScreen.getmLobbyView().showLeague();
				}
			}else{
				mMainScreen.showLobbyView(true);
				mMainScreen.getmLobbyView().showLeagueRooms(Utils.getLeagueId());
			}
			System.out.println("Current League Id: " + Utils.getLeagueId());
		}
		
		
		//System.out.println("Back2 " + mMainScreen.getRooms().size() );
		//
	}

}
